#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, left, right;
    cin >> n;
    vector<int> a(n), sum(n + 1);
    for (int i = 0; i < n && cin >> a[i]; ++i);

    sum[0] = 0;
    for (int i = 1; i <= n; ++i)
        sum[i] = sum[i - 1] + a[i - 1];

    cin >> m;
    for (; m != 0; --m) {
        cin >> left >> right;
        if (left >= 1 && left <= right && right <= n) {
            cout << sum[right] - sum[left - 1] << endl;
        }
    }

    cin.get();
    return 0;
}